package com.sansui.admin.core.ctrl;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.sansui.admin.common.constant.Action;
import com.sansui.admin.common.ctrl.BaseCtrl;
import com.sansui.admin.core.groups.RoleAdd;
import com.sansui.admin.core.groups.RoleUpdate;
import com.sansui.admin.core.model.RoleAddModel;
import com.sansui.admin.core.model.RolePage;
import com.sansui.admin.core.service.RoleService;

@RestController
@RequestMapping("/system/role")
public class RoleController extends BaseCtrl {
	@Autowired
	private RoleService roleService;

	@RequiresPermissions(_ROLE_ROUTE + Action._LIST)
	@RequestMapping(value = Action._LIST)
	public Object list(HttpServletRequest request, RolePage role) {
		return roleService.findTByPage(role);
	}

	@RequiresPermissions(_ROLE_ROUTE + Action._ADD)
	@RequestMapping(value = Action._ADD)
	public Object add(@Validated({ RoleAdd.class }) RoleAddModel role, BindingResult bindingResult) {
		return roleService.insertRole(role);
	}

	@RequiresPermissions(_ROLE_ROUTE + Action._DELETE)
	@RequestMapping(value = Action._DELETE)
	public Object delete(String[] id) {
		return roleService.deleteRole(id);

	}

	@RequiresPermissions(_ROLE_ROUTE + Action._UPDATE)
	@RequestMapping(value = Action._UPDATE)
	public Object update(@Validated({ RoleUpdate.class }) RoleAddModel mrole, BindingResult bindingResult) {
		return roleService.updateRole(mrole);
	}

	@RequestMapping(value = "/listAll")
	public Object listAll() {
		return roleService.selectAll();
	}

	@RequestMapping(value = Action._SPRIMARY)
	public Object selectByPrimaryKey(String id) {
		return roleService.selectByPrimaryKey(id);
	}

}
